﻿using Newtonsoft.Json;
using NLog;
using OrBitDataModule.Adaptor;
using OrBitDataModule.Base;
using OrBitDataModule.Common;
using OrBitDataModule.FileHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace OrBitDataModule.Interface
{
    public interface IContext
    {
        DataTaskBase DataTask { get; }

        /// <summary>
        /// 默认编码
        /// </summary>
        Encoding DefaultEncoding { get; }

        /// <summary>
        /// 任务唯一码
        /// </summary>
        string UniqueId { get; }

        /// <summary>
        /// 任务名称
        /// </summary>
        string TaskName { get; }

        /// <summary>
        /// Webapi基础地址
        /// </summary>
        string BaseApiUri { get; }

        /// <summary>
        /// 接口用户名
        /// </summary>
        string UserName { get; }

        /// <summary>
        /// 接口名称
        /// </summary>
        string ApiName { get; }

        /// <summary>
        /// 登录接口token
        /// </summary>
        string Token { get; }
        /// <summary>
        /// 接口有效期
        /// </summary>
        int Expiration { get; }
        /// <summary>
        /// 设置参数
        /// </summary>
        SettingDictionary SettingProperty { get; }
        /// <summary>
        /// 串口对象
        /// </summary>
        SerialPort SerialPortInstance { get; }
        /// <summary>
        /// Socket Client对象
        /// </summary>
        SocketTcpClient TcpClientInstance { get; }
        /// <summary>
        /// 定时调度器
        /// </summary>
        QuartzScheduler Scheduler { get; }
        /// <summary>
        /// http请求对象
        /// </summary>
        HttpLib.Http Http { get; }

        /// <summary>
        /// 获取api token
        /// </summary>
        /// <param name="apiName"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        Task<(bool Result, string Token, int Expiration, string Message)> GetWebApiToken(string apiName, string userName, string password);

        /// <summary>
        /// /序列化json
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        string SerializeToJson<T>(T obj);

        /// <summary>
        /// 反序列化json
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="json"></param>
        /// <returns></returns>
        T DeserializeObject<T>(string json);

        /// <summary> 
        /// 实体对象序列化成xml字符串 
        /// </summary> 
        /// <typeparam name="T"></typeparam> 
        /// <param name="obj"></param> 
        /// <returns></returns> 
        string SerializeToXML<T>(T obj, Encoding encoding = null);

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        void WriteLog(string message);

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="logLevel"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        void WriteLog(string message, LogLevel logLevel);

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="taskName"></param>
        /// <param name="message"></param>
        /// <param name="logLevel"></param>
        /// <returns></returns>
        void WriteLog(string taskName, string message, LogLevel logLevel);
    }
}
